/******************************************************************************
** 
** File name:	UTEST_02.c
**	
** Description:	RTOS Ver.3 Unit Tests. Basic RTOS Task services from
**				the task execution level (no interrupts).
**
** RTOS API Services to be checked:
**
**		- RTOS_TaskResume()
**		- RTOS_TaskSuspend()
**
** Notes:	PASSED
**
*******************************************************************************
**
** Change history:
**	
** 10/01/2012 -AK- 	File created
**
******************************************************************************/
#include <avr/io.h>
#include <avr/interrupt.h>

#ifndef UTEST_02
#	error "UTEST_02 must be defined as -D$(Configuration) compiler option"
#endif

#include "UTEST_RES.h"

/******************************************************************************
**	UNIT TEST INTERRUPT FUNCTION[s]
******************************************************************************/

// N/A

/******************************************************************************
**	UNIT TEST TASK FUNCTION[s]
******************************************************************************/
/*
** RTOS Task #0 - Stack checking task
*/
RTOS_TASK_FUNC(tsk0)
{
	while (1)
	{	
		RTOS_DebugPrint("[T0] Checking stacks consistency");

		RTOS_StackCheck(tsk0);
		RTOS_StackCheck(tsk1);
		RTOS_StackCheck(tsk2);
		RTOS_StackCheck(tsk3);
		
		RTOS_TaskSuspend(&tsk0PID);
		
	}
}

/*
** RTOS Task #1
*/
RTOS_TASK_FUNC(tsk1)
{
	RTOS_DebugPrint("\t[T1] Started");
	while(1)
	{
		RTOS_DebugPrint("\t[T1] Suspending...");
		RTOS_TaskSuspend(&tsk1PID);
		RTOS_DebugPrint("\t[T1] Resumed");	
		RTOS_TaskResume(&tsk0PID);		// check stack consistency
	}
}

/*
** RTOS Task #2 
*/
RTOS_TASK_FUNC(tsk2)
{
	RTOS_DebugPrint("\t\t[T2] Started");
	while(1)
	{
		RTOS_DebugPrint("\t\t[T2] Suspending...");
		RTOS_TaskSuspend(&tsk2PID);		
		RTOS_DebugPrint("\t\t[T2] Resumed");		
		RTOS_TaskResume(&tsk0PID);		// check stack consistency
	}
}

/*
** RTOS Task #3 
*/
RTOS_TASK_FUNC(tsk3)
{
	RTOS_DebugPrint("\t\t\t[T3] Started");
	while(1)
	{
		RTOS_DebugPrint("\t\t\t[T3] Resuming Task #1 ...");
		RTOS_TaskResume(&tsk1PID);
		
		RTOS_TaskResume(&tsk0PID);		// check stack consistency
		
		RTOS_DebugPrint("\t\t\t[T3] Resuming Task #2 ...");
		RTOS_TaskResume(&tsk2PID);
		
		RTOS_TaskResume(&tsk0PID);		// check stack consistency
	}
}

